<template>
  <div class="user_list-page ">
    <div class="user_list-page" style="margin-bottom: 20px;">
      <div class="pageHead">
        <p>场景集查询</p>
      </div>
      <!--      场景集搜索-->
      <div class="pageHead">
        <Form ref="testsuiteForm" :model="testsuiteForm" inline :label-width="90">
          <FormItem label="所属项目" prop="project">
            <Select v-model="testsuiteForm.project" style="width:200px" clearable>
              <Option v-for="(item, index) in projectNames" :value="item.id" :key="item.id">{{
                  item.name
                }}
              </Option>
            </Select>
          </FormItem>

          <FormItem label="场景集名称" prop="name">
            <Input
                type="text"
                v-model="testsuiteForm.name"
                placeholder="请输入接口名称"
                clearable
                style="width: 200px"
            />
          </FormItem>

          <FormItem label="测试场景" prop="testsuite">
             <Select v-model="testsuiteForm.testsuite" style="width:200px" clearable>
              <Option v-for="(item, index) in Belongstesuite" :value="item.id" :key="item.id">{{
                  item.name
                }}
              </Option>
            </Select>
          </FormItem>

          <FormItem label="重要级别" prop="level">
            <Select v-model="testsuiteForm.level" style="width:200px" clearable>
              <!--                    <Option v-for="(item, index) in projectnames" :value="item.id" :key="item.id">{{ item.name }}</Option>-->
              <Option :value="0">低</Option>
              <Option :value="1">中</Option>
              <Option :value="2">高</Option>
              <Option :value="3">更高</Option>
            </Select>
          </FormItem>
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="testsuitequery" type="primary" icon="ios-search" style="
                   margin-right: 10px;"
            >搜索
            </Button>
            <Button @click="suitesetreset('testsuiteForm')">重置</Button>
          </FormItem>
        </Form>
      </div>
    </div>
    <!--    场景集界面-->
    <div class="pageHead">
      <div style="display: flex;justify-content: space-between">
        <p>场景集列表</p>
        <div>
          <Icon type="ios-leaf" size="24" color="rgb(45, 183, 245)"/>
          <i style="margin-right: 15px;">初始状态</i>
          <Icon type="ios-leaf" size="24" color="rgb(25, 190, 107)"/>
          <i style="margin-right: 15px;">全部通过</i>
          <Icon type="ios-leaf" size="24" color="rgb(255, 153, 0)"/>
          <i style="margin-right: 15px;">部分通过</i>
          <Icon type="ios-leaf" size="24" color="rgb(237, 64, 20)"/>
          <i style="margin-right: 15px;">失败</i>
          <Button type="primary" size="small" @click="testsuitesetModal=true">创建场景集</Button>
          <Button type="primary" size="small" @click="testsuiteBatch" style="margin-left: 10px;">批量执行</Button>
          <Button type="error" size="small" style="margin-left: 10px;" @click="testsuitesetde">删除</Button>
        </div>
      </div>
    </div>
    <!--    场景集列表-->
    <div class="pageHead">
      <!--           场景集列表渲染-->
      <Table
          border
          :columns="suitesetcolumns"
          @on-selection-change="testsuiteselectFun"
          :data="suitesetdata"
          sortable="custom"
          ref="table"
          size="small"
      >
        <template slot-scope="{ row }" slot="project">
          <strong>{{ row.project.name }}</strong>
        </template>

        <template slot-scope="{ row }" slot="testsuite">
          <!--                <strong>{{ row.testcases.name }}</strong>-->
          <samp v-for="(item ,index) in listSplice(row.testsuite)">
            <Tag color="green">{{ item.name }}</Tag>
          </samp>
        </template>

        <template slot-scope="{ row }" slot="status">
          <Icon v-if="row.status == 'INITIAL'" type="ios-leaf" size="24" color="rgb(45, 183, 245)"/>
          <Icon v-if="row.status == 'PASS'" type="ios-leaf" size="24" color="rgb(25, 190, 107)"/>
          <Icon v-if="row.status == 'FAIL'" type="ios-leaf" size="24" color="rgb(237, 64, 20)"/>
          <Icon v-if="row.status == 'PARTIAL_PASS'" type="ios-leaf" size="24" color="rgb(255, 153, 0)"/>
        </template>

        <template slot-scope="{ row }" slot="level">
          <Select v-model="row.level" style="width:80px" prefix="ios-home" @on-change="testsuitesetpartials(row)"
                  transfer>
            <div slot="prefix" class="box"
                 :style="{'background-color':row.level === 'LOW' ? '#2db7f5':row.level === 'NORMAL' ? '#19be6b' :row.level==='HIGH' ? '#f90' :'#ed4014' }"></div>
            <Option v-for="item in levelList" :value="item.value" :key="item.name">
              {{ item.name }}
            </Option>
          </Select>
        </template>

      </Table>
            <div>
              <Page
                  :total="suitesetlist.total"
                  :page-size="suitesetlist.size"
                  :current="suitesetlist.index"
                  show-total
                  show-elevator
                  show-sizer
                  @on-change="suitelistpageSize"
                  @on-page-size-change="suitelistpagePage"
                  style="margin-top: 20px;"

              />
            </div>
    </div>

    <!--              创建场景集-->
    <Modal v-model="testsuitesetModal" width="950" title="创建场景集">
      <Form ref="crtestsuiteset" :model="crtestsuiteset" :rules="create_ruleValidate">
        <div>
          <FormItem label="场景集名称" prop="name">
            <Input
                type="text"
                v-model="crtestsuiteset.name"
                clearable
                style="width: 800px"
            />
          </FormItem>
        </div>

        <div>
          <FormItem label="所属项目" prop="project" style="margin-left: 14px;">
            <Select v-model="crtestsuiteset.project" style="width:800px">
              <Option v-for="(item, index) in projectNames" :value="item.id" :key="item.id">{{
                  item.name
                }}
              </Option>
            </Select>
          </FormItem>
        </div>

        <div>
          <FormItem label="发送报告(钉钉)" style="margin-left: 36px;">
            <i-switch v-model="crtestsuiteset.dingTalk">
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
          </FormItem>
        </div>

        <div>
          <FormItem label="备注" style="margin-left: 52px;">
            <Input
                type="textarea"
                v-model="crtestsuiteset.desc"
                :rows=5
                style="width: 800px"
            />
          </FormItem>
        </div>
      </Form>
      <div slot="footer">
        <Button @click="testsuitesetModal = false">取消</Button>
        <Button @click="cretestsuiteset('crtestsuiteset')" type="primary">确定</Button>
      </div>
    </Modal>

    <!--              编辑场景集-->
    <Modal v-model="updatesuitesetModal" width="950" title="编辑场景集">
      <Form ref="uptestsuiteset" :model="uptestsuiteset" :rules="update_ruleValidate">
        <div>
          <FormItem label="场景集名称" prop="name">
            <Input
                type="text"
                v-model="uptestsuiteset.name"
                clearable
                style="width: 800px"
            />
          </FormItem>
        </div>

        <div>
          <FormItem label="所属项目" prop="project" style="margin-left: 14px;">
            <Select v-model="uptestsuiteset.project" style="width:800px" disabled>
              <Option v-for="(item, index) in projectNames" :value="item.id" :key="item.id">{{
                  item.name
                }}
              </Option>
            </Select>
          </FormItem>
        </div>

        <div>
          <FormItem label="发送报告(钉钉)" style="margin-left: 36px;">
            <i-switch v-model="uptestsuiteset.dingTalk">
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
          </FormItem>
        </div>

        <div>
          <FormItem label="备注" style="margin-left: 52px;">
            <Input
                type="textarea"
                v-model="uptestsuiteset.desc"
                :rows=5
                style="width: 800px"
            />
          </FormItem>
        </div>
      </Form>
      <div slot="footer">
        <Button @click="updatesuitesetModal = false">取消</Button>
        <Button @click="upetestsuiteset('uptestsuiteset')" type="primary">确定</Button>
      </div>
    </Modal>

    <!--              组织场景-->
    <Modal v-model="assemble" fullscreen title="项目：">
      <!--                场景源-->
      <div class="suiteroot">
        <div style="border: 1px solid #dcdee2;">
          <div class="testcase" style="padding-bottom: 16px">
            <span>场景源</span>
            <div style="display: inline-block;justify-content: space-between;float:right">
              <Button @click="suiterootsearch" type="primary" icon="ios-search" size='small'
                      style="margin-right: 10px;">搜索
              </Button>
              <Button @click="suiterootreset('assembleForm')" size='small'>重置</Button>
            </div>
          </div>
        </div>
        <div style="border: 1px solid #dcdee2;">

          <div style="margin-top: 15px;">
            <Form ref="assembleForm" :model="assembleForm" inline :label-width="120">
              <FormItem label="所属项目" prop="project">
                <Select v-model="assembleForm.project" style="width:440px" clearable>
                  <Option v-for="(item, index) in projectNames" :value="item.id" :key="item.id">{{
                      item.name
                    }}
                  </Option>
                </Select>
              </FormItem>


              <FormItem label="场景名称" prop="name">
                <Input
                    type="text"
                    v-model="assembleForm.name"
                    placeholder="请输入场景名称"
                    clearable
                    style="width: 300px"
                />
              </FormItem>

              <FormItem label="重要级别" prop="level">
                <Select v-model="assembleForm.level" style="width:300px" clearable>
                  <Option :value="0">低</Option>
                  <Option :value="1">中</Option>
                  <Option :value="2">高</Option>
                  <Option :value="3">更高</Option>
                </Select>
              </FormItem>
            </Form>
          </div>

          <Table
              border
              :columns="assemblecolumns"
              :data="assembledata"
              sortable="custom"
              ref="table"
              size="small"
              style="clear:both;width: 1836px;margin-left: 15px;"
          >
            <template slot-scope="{ row }" slot="project">
              <strong>{{ row.project.name }}</strong>
            </template>

            <template slot-scope="{ row }" slot="testcases">
              <!--                <strong>{{ row.testcases.name }}</strong>-->
              <samp v-for="(item ,index) in listSplice(row.testcases)">
                <Tag color="green">{{ item.name }}</Tag>
              </samp>
            </template>

            <template slot-scope="{ row }" slot="status">
              <Icon v-if="row.status == 'INITIAL'" type="ios-leaf" size="24" color="rgb(45, 183, 245)"/>
              <Icon v-if="row.status == 'PASS'" type="ios-leaf" size="24" color="rgb(25, 190, 107)"/>
              <Icon v-if="row.status == 'FAIL'" type="ios-leaf" size="24" color="rgb(237, 64, 20)"/>
            </template>

            <template slot-scope="{ row }" slot="level">
              <Select v-model="row.level" style="width:80px" prefix="ios-home" @on-change="partials(row)"
                      transfer>
                <div slot="prefix" class="box"
                     :style="{'background-color':row.level === 'LOW' ? '#2db7f5':row.level === 'NORMAL' ? '#19be6b' :row.level==='HIGH' ? '#f90' :'#ed4014' }"></div>
                <Option v-for="item in levelList" :value="item.value" :key="item.name">
                  {{ item.name }}
                </Option>
              </Select>
            </template>

            <template slot-scope="{ row }" slot="action">
              <Button style="color: #2d8cf0" @click="addsuiteset(row)" ghost>选择</Button>
            </template>

          </Table>
          <div style="margin-bottom: 15px;">
            <Page
                :total="suitesetrootpage.total"
                :page-size="suitesetrootpage.size"
                :current="suitesetrootpage.index"
                show-total
                show-elevator
                show-sizer
                @on-change="suitesetourcepageSize"
                @on-page-size-change="suitesetourcepagePage"
                style="margin-top: 20px;padding-left: 16px;"

            />
          </div>
        </div>
      </div>

      <!--      组织场景集列表-->
      <div class="suiterootlist">
        <div style="border: 1px solid #dcdee2;margin-top: 15px">
          <div class="testcase" style="padding-bottom: 16px">
            <span>组织场景 (拖动调整顺序)</span>
          </div>
        </div>

        <div style="border: 1px solid #dcdee2;padding-top: 20px;padding-bottom: 20px;">
          <Table
              border
              draggable
              @on-drag-drop="onDragDrop"
              :columns="testsuitesetcolumns"
              :data="testsuitesetdata"
              sortable="custom"
              ref="selection"
              size="small"
              style="clear:both;width: 1836px;margin-left: 15px;"
          >
            <template slot-scope="{ row }" slot="testsuite_name">
              <Input v-model="row.testsuite_name" style="width: 260px" readonly/>
            </template>

            <template slot-scope="{ row }" slot="project">
              <strong>{{ row.testsuite.project.name }}</strong>
            </template>

            <template slot-scope="{ row }" slot="frequency">
              <InputNumber v-model="row.loop_count" :max="10" :min="1"
                           @on-change="loop_count_changge(row._index, row.loop_count)"></InputNumber>
            </template>

           <template slot-scope="{ row }" slot="testcases">
              <!--                <strong>{{ row.testcases.name }}</strong>-->
              <samp v-for="(item ,index) in listSplice(row.testsuite.testcases)">
                <Tag color="green">{{ item.name }}</Tag>
              </samp>
            </template>

            <template slot-scope="{ row }" slot="action">
              <i-switch size="large" v-model="row.is_execute" @on-change="change(row)">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
              </i-switch>
              <Button type="text" ghost style="color: #f5222d" @click="deletetestcase(row)">移除</Button>
            </template>

          </Table>
        </div>
      </div>


      <div slot="footer">
        <Button @click="assemble = false">取消</Button>
        <Button @click="assembleconfirm" type="primary">确定</Button>
      </div>
    </Modal>


  </div>
</template>

<script>
import {
  testsuitelist,
  testsuiteset_create,
  testsuiteset_list,
  testsuiteset_partial,
  testsuiteset2testsuite,
  testsuiteset2testsuite_list,
  testsuite_Batch, testsuiteset_Batch, suiteset_Batch_Delete, suiteset_update, testcaselist
} from "../../api/api";

export default {
  name: "testsuite_set",
  props: {
    projectNames: Array, // 项目名称列表
    Belongstesuite: Array, // 场景列表
  },
  created() {
    this.testsuiteset()
  },
  data() {
    return {
      // 场景集组织场景源
      suitesetrootpage: {
        index: 1,
        size: 10,
        total: 50
      },
      // 场景集列表
      suitesetlist:  {
        index: 1,
        size: 10,
        total: 50
      },
      create_ruleValidate: {
        name: [
          {required: true, message: '请输入场景集名称', trigger: 'blur'}
        ],
        project: [
          {required: true, message: '请选择所属项目', trigger: 'blur'},
        ]
      },
      update_ruleValidate: {
        name: [
          {required: true, message: '请输入场景集名称', trigger: 'blur'}
        ],
        project: [
          {required: true, message: '请选择所属项目', trigger: 'blur'},
        ]
      },
      testsuiteMultilineId:[],
      testsuitesetdata:[],
      levelList: [
        {
          name: '低',
          value: 'LOW'
        },
        {
          name: '中',
          value: 'NORMAL'
        },
        {
          name: '高',
          value: 'HIGH'
        },
        {
          name: '更高',
          value: 'HIGHER'
        }
      ],
      update_id: '',
      testsuite_set_id:[],
      suitesetdata: [],
      assembledata: [],
      assembleForm: {},
      testsuitesetModal: false, //创建场景集Modal
      updatesuitesetModal: false, //编辑场景集Modal
      assemble: false, //组织场景集Modal
      crtestsuiteset: {
        name: '',
        project: '',
        desc: '',
        dingTalk: false
      },
      uptestsuiteset: {
        name: '',
        project: '',
        desc: '',
        dingTalk:false
      },
      // 场景集搜索from
      testsuiteForm: {
        project: '',
        name: '',
        level: null
      },
      suitesetcolumns: [
        {
          type: 'selection',
          width: 60,
          align: "center",
        },
        {
          title: "场景集名称",
          key: "name",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "所属项目",
          slot: "project",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "测试场景",
          slot: "testsuite",
          align: "center",
          width: 529,
        },
        {
          title: "重要级别",
          slot: "level",
          align: "center",
          width: 120,
          fixed: "right",
        },
        {
          title: "状态",
          slot: "status",
          align: "center",
          width: 70,
          fixed: "right",

        },
        {
          title: "操作",
          key: "action",
          align: "center",
          width: 190,
          fixed: "right",
          render: (h, params) => {
            let enableOrDisable = "";
            return h("div", [
              h(
                  "a",
                  {

                    on: {
                      click: () => {
                        this.edit('crenvs2', params.row);
                      },
                    },
                  },
                  "复制"
              ),
              h("Divider", {
                props: {
                  type: "vertical",
                },
              }),
              h(
                  "a",
                  {
                    style: {
                      color: '#2D8CF0'
                    },
                    on: {
                      click: () => {
                        this.upsuiteset(params.row);
                      },
                    },
                  },
                  "编辑"
              ),

              enableOrDisable,
              h("Divider", {
                props: {
                  type: "vertical",
                },
              }),
              h(
                  "a",
                  {
                    style: {
                      color: '#2D8CF0'
                    },
                    on: {
                      click: () => {
                        this.assembleset(params.row);
                      },
                    },
                  },
                  "组织场景集"
              )

            ])
                ;

          },
        },
      ],
      assemblecolumns: [
        {
          title: "场景名称",
          key: "name",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "所属项目",
          slot: "project",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "测试用例",
          slot: "testcases",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "创建时间",
          key: "create_time",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "修改时间",
          key: "update_time",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "重要级别",
          slot: "level",
          align: "center",
          width: 120,
          fixed: "right",
        },
        {
          title: "状态",
          slot: "status",
          align: "center",
          width: 70,
          fixed: "right",
        },
        {
          title: "操作",
          slot: "action",
          align: "center",
          width: 190,
          fixed: "right",
        },
      ],
      testsuitesetcolumns: [
        {
          title: "场景名称",
          slot: "testsuite_name",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "所属项目",
          slot: "project",
          align: "center",
          minWidth: 125,
          width: 300,
        },
        {
          title: "循环次数",
          slot: "frequency",
          align: "center",
          width: 120,
        },
        {
          title: "测试用例",
          slot: "testcases",
          align: "center",
        },
        {
          title: "操作",
          slot: "action",
          align: "center",
          width: 190,
          fixed: "right",
          renderHeader: (h, params) => {
            return h(
                'div',
                {
                  style: {
                    display: 'flex',
                    justifyContent: 'space-between',
                    alignItems: 'center'
                  }
                },
                [
                  h('div', '操作'),

                  h('Button', {
                    props: {
                      type: "text",//类型
                      size: "small",//尺寸
                    },
                    style: {
                      color: '#ed4014',
                      marginLeft: '5px'
                    },
                    on: {
                      click: () => {
                        this.testsuitesetdata = []
                      }
                    },
                  }, '清空')

                ])
          }
        },
      ],
    }
  },
  methods: {
    // 组织场景源翻页
    suitesetourcepageSize(e) {
      let data = {
        'size': this.suitesetrootpage.size,
        'page': e
      }
      testsuitelist(data).then(res => {
        this.assembledata = res.data.data
        this.suitesetrootpage.total = res.data.count
      })
    },
    suitesetourcepagePage(e) {
       let data = {
        'size': e,
        'page': this.suitesetrootpage.index
      }
      testsuitelist(data).then(res => {
        this.assembledata = res.data.data
        this.suitesetrootpage.total = res.data.count
      })
    },

    // 场景集列表翻页
    suitelistpageSize(e) {
       let data = {
        'size': this.suitesetlist.size,
        'page': e
      }
      testsuiteset_list(data).then(res => {
        this.suitesetdata = res.data.data
        this.suitesetlist.total = res.data.count
      })
    },
    suitelistpagePage(e) {
      let data = {
        'size': e,
        'page': this.suitesetlist.index
      }
      testsuiteset_list(data).then(res => {
        this.suitesetdata = res.data.data
        this.suitesetlist.total = res.data.count
      })
    },

    // 批量删除
    testsuitesetde() {
      let list = []
      for (let i=0; i<this.testsuiteMultilineId.length; i++){
        list.push(this.testsuiteMultilineId[i].id)
      }
      suiteset_Batch_Delete(list).then(res => {
        this.testsuiteset()
      })
    },
    //场景集列表选择ID
    testsuiteselectFun(row) {
      this.testsuiteMultilineId = row
    },

    // 批量执行
    testsuiteBatch(){
      let list = []
      let data = this.testsuiteMultilineId
      for (var i = 0; i < data.length; i++) {
        if (data[i].testsuite.length = 0) {
          this.$Message.error('请先添加组织场景！')
        } else {
          list.push(data[i].id)
        }
      }
      if (list.length > 0) {
        testsuiteset_Batch(list).then(res => {
          this.$Message.success(res.msg)
        })

      }
    },
    change(row) {
      this.$set(this.testsuitesetdata[row._index], 'is_execute', row.is_execute)
    },

    loop_count_changge(index, loop_count) {
      this.testsuitesetdata[index].loop_count = loop_count
    },

    assembleconfirm() {
      for (let i=0;i<this.testsuitesetdata.length;i++){
      console.log(this.testsuitesetdata[i].sort)
        if (typeof(this.testsuitesetdata[i].sort) == 'undefined'){
            this.testsuitesetdata[i].sort = i
            delete this.testsuitesetdata[i].testsuite
        }else {
            this.testsuitesetdata[i].testsuite_set_id = this.testsuitesetdata[i].testsuite_set
            this.testsuitesetdata[i].testsuite_id = this.testsuitesetdata[i].testsuite.id
            delete this.testsuitesetdata[i].testsuite
            delete this.testsuitesetdata[i].testsuite_set
        }

      }
      let data = {
        "testsuite_set_id":this.testsuite_set_id.id,
        "data":this.testsuitesetdata
      }
      testsuiteset2testsuite(data).then(res =>{
        this.$Message.success(res.msg)
        this.assemble = false
        this.testsuiteset()
      })
    },

    // 组织详情页移除按钮
    deletetestcase(row) {
      console.log(row._index)
      this.testsuitesetdata.splice(row._index, 1)
    },
    // 选择
    addsuiteset(row) {
      this.testsuitesetdata.push({
        "testsuite_id": row.id,
        "testsuite_name": row.name,
        "testsuite_set_id": this.testsuite_set_id.id,
        "testsuite_set_name": this.testsuite_set_id.name,
        "testsuite":row
      })
      console.log(this.testsuitesetdata)
    },

    // 组织场景集按钮
    assembleset(row) {
      this.testsuite_set_id = row
      testsuitelist({'project': row.project.id}).then(res => {
        this.assembledata = res.data.data
        this.suitesetrootpage.total = res.data.count
      })
      this.assemble = true

      testsuiteset2testsuite_list({'testsuite_set':this.testsuite_set_id.id}).then(res =>{
        let data = res.data.data
        this.testsuitesetdata = data
      })
    },
    // 场景集搜索
    testsuitequery() {
      let data = {
        project: this.testsuiteForm.project,
        name: this.testsuiteForm.name,
        level: this.testsuiteForm.level === 0 ? "LOW" : this.testsuiteForm.level === 1 ? "NORMAL" : this.testsuiteForm.level === 2 ? "HIGH" : this.testsuiteForm.level === 3 ? "HIGHER" : "",
        testsuite: this.testsuiteForm.testsuite
      }
      testsuiteset_list(data).then(res => {
        this.suitesetdata = res.data.data
        this.suitesetlist.total = res.data.count
      })
    },

    // 组织场景搜索
    suiterootsearch() {
      let data = {
        project: this.assembleForm.project,
        name: this.assembleForm.name,
        level: this.assembleForm.level === 0 ? "LOW" : this.assembleForm.level === 1 ? "NORMAL" : this.assembleForm.level === 2 ? "HIGH" : this.assembleForm.level === 3 ? "HIGHER" : "",
      }
      testsuitelist(data).then(res => {
        this.assembledata = res.data.data
      })
    },
    // 组织场景重置
    suiterootreset(name) {
       testsuitelist({'project': this.testsuite_set_id.project.id}).then(res => {
         this.assembledata = res.data.data
         this.$refs[name].resetFields();
       })
    },

    // 场景集重置
    suitesetreset(name){
      this.testsuiteset()
      this.$refs[name].resetFields();
    },

    // 场景集列表场景过长切割
    listSplice(row) {
      if (row.length > 10) {
        // row.push({'name': '.....'})
        row = row.slice(0, 10)
        row.push({'name': '...'})
        return row
      } else {
        return row
      }
    },
    testsuiteset() {
      testsuiteset_list().then(res => {
        let data = res.data.data
        this.suitesetdata = data
        this.suitesetlist.total = res.data.count
      })
    },

    // 场景集重要级别修改
    testsuitesetpartials(row) {
      const datas = {
        'level': row.level
      }
      testsuiteset_partial(row.id, datas).then(res => {
        this.$Message.success('已更新场景权重值!')
      })
    },

    // 创建场景集
    cretestsuiteset(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          debugger
          testsuiteset_create(this.crtestsuiteset).then(res => {
          this.$Message.success(res.msg)
          this.testsuitesetModal = false
          this.testsuiteset()
        })
        }
      })

    },
    // 编辑按钮
    upsuiteset(pw) {
      this.update_id = pw.id
      this.updatesuitesetModal = true
      this.uptestsuiteset.name = pw.name
      this.uptestsuiteset.project = pw.project.id
      this.uptestsuiteset.dingTalk = pw.dingTalk
      this.uptestsuiteset.desc = pw.desc
    },
    // 编辑场景
    upetestsuiteset(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          suiteset_update(this.update_id, this.uptestsuiteset).then(res => {
            this.$Message.success(res.msg)
            this.updatesuitesetModal = false
            this.testsuiteset()
          })
        }
      })
    },

    onDragDrop(first, end) {
      first = parseInt(first)
      end = parseInt(end)
      let tmp = this.testsuitesetdata[first]

      if (first < end) {
        for (var i = first + 1; i <= end; i++) {
          this.testsuitesetdata.splice(i - 1, 1, this.testsuitesetdata[i])
        }
        this.testsuitesetdata.splice(end, 1, tmp)
      }

      if (first > end) {
        for (var y = first; y > end; y--) {
          this.testsuitesetdata.splice(y, 1, this.testsuitesetdata[y - 1])
        }
        this.testsuitesetdata.splice(end, 1, tmp)
      }

      //重置排序值
      let index = 1
      this.testsuitesetdata.forEach(e => {
        e.sort = index
        index++
      })
      //排序值重置后，向后台发送请求，更新数据库中数据的排序，这里就不写了
      //axios

    },
  },
}
</script>

<style scoped>

</style>
